package com.lihao.baselibrary.weight;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lihao.baselibrary.R;


/**
 * 自定义加载条
 * 
 * @author zxm com.yaoyu.hechuan.view.LoadingProgress
 */
public class LoadingProgress extends RelativeLayout {

	private Context context;
    private View view;
	private LinearLayout loadingLayout;
	private TextView failureText;

	public LoadingProgress(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
	}

	public LoadingProgress(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public LoadingProgress(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		this.context = context;
		init();
	}

	private void init() {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		view = inflater.inflate(R.layout.progress_bar_layout, this);
		failureText = (TextView) view.findViewById(R.id.loading_failure_text);
		loadingLayout = (LinearLayout) view.findViewById(R.id.base_landing_lay);
	}

	/**
	 * 加载失败,应用于网络加载后，列表无数据的情况，网络有问题但读取缓存有数据还应该视为加载成功
	 */
	public void loadingFailure() {
		loadingLayout.setVisibility(View.GONE);
		failureText.setVisibility(View.VISIBLE);
		view.setOnTouchListener(new OnTouchListener() {

			@SuppressLint("ClickableViewAccessibility")
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				return true;
			}
		});
	}

	/**
	 * 加载成功
	 */
	public void loadingSuccess() {
		loadingLayout.setVisibility(View.GONE);
	}

}
